<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="formTest">
    <!--    记录id,方便修改-->
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户姓名：</label>
        <div class="layui-input-block">
            <input type="text" name="name" readonly lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别：</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" readonly checked="">
            <input type="radio" name="sex" readonly value="2" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">手机号码：</label>
        <div class="layui-input-block">
            <input type="number" name="phone" readonly lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">申请挂号时间：</label>
        <div class="layui-input-block">
            <input id="date" name="registertime" placeholder="请选择预约时间" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="registerBtn">立即挂号</button>
        </div>
    </div>
</div>
</div>
<div class="layui-form layuimini-form" lay-filter="formdDoc">
    <!--    记录id,方便修改-->
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label required">医生姓名：</label>
        <div class="layui-input-block">
            <input type="text" name="name" readonly lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">医生性别：</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" readonly checked="">
            <input type="radio" name="sex" readonly value="2" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">医生手机：</label>
        <div class="layui-input-block">
            <input type="number" name="phone" readonly lay-verify="required" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" hidden>
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn"></button>
        </div>
    </div>
</div>
</div>
<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    $(function (){
        var json=localStorage.getItem("doctor");
        var doctor =JSON.parse(json);
        var u;
        layui.use(['form','laydate'], function () {
            var form = layui.form,
                layer = layui.layer,
                laydate=layui.laydate,
                $ = layui.$;
            $.get("/api/usersession/getuser.do",function (res){
                //渲染用户信息
                u=res.data
                form.val("formTest", res.data);
                console.log(u);
            })
            $.get('/employee/selectPage.do?name='+doctor.department_employee_name+"&page=1&limit=1",function (res){
                    //渲染日期框
                    laydate.render({
                        elem: '#date' //指定元素
                    });
                    //渲染医生信息
                    form.val("formdDoc", res.data[0]);


                    //获取当前的医生对象
                    docs = res.data[0]

                    //监听提交，实现数据修改
                    form.on('submit(registerBtn)', function (data) {
                        var now = new Date();
                        var year = now.getFullYear(); //得到年份
                        var month = now.getMonth();//得到月份
                        var date = now.getDate();//得到日期
                        month = month + 1;
                        if (month < 10) month = "0" + month;
                        if (date < 10) date = "0" + date;
                        var current = year + "-" + month + "-" + date;    //（格式化"yyyy-MM-dd"）
                        // current = new Date().Format("yyyy-MM-dd")
                        console.log(current);
                        console.log(data.field.registertime);
                        console.log(data.field.registertime>current)
                        if(data.field.registertime>current){
                            var register={
                                'uid':u.id+'',
                                'registertime':data.field.registertime,
                                'depid':docs.dp_id+'',
                                'empid':docs.id+''
                            }

                            // 请求接口 Ajax
                            $.post("/api/register/addregister.do",register,function (res){
                                if(res.code==200){
                                    parent.layui.table.reload('currentTableId');
                                    // 关闭弹出层
                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(iframeIndex);
                                }else {
                                    layer.msg("亲，挂号失败！");
                                }
                            })
                            // return false;
                        }else {
                            alert("请选择正确的日期时间")
                        }

                    });

                });
        })
    })

</script>
</body>
</html>